package com.atguigu.dga.meta.mapper;

import com.atguigu.dga.meta.bean.TableMetaInfo;
import com.atguigu.dga.meta.bean.TableMetaInfoVO;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 元数据表 Mapper 接口
 * </p>
 *
 * @author zhangchen
 * @since 2024-07-24
 */
@Mapper
@DS("dga")
public interface TableMetaInfoMapper extends BaseMapper<TableMetaInfo> {

    @Select("${sql}")
    List<TableMetaInfoVO> selectTableMetaListForQuery(@Param("sql") String sql);

    @Select("${sql}")
    Integer selectTableMetaTotalForQuery(@Param("sql") String string);

    @Select("   select tm.id as tm_id ,te.id as te_id ,tm.create_time as tm_create_time ," +
            " te.create_time as te_create_time ,tm.update_time as tm_update_time, te.update_time as te_update_time," +
            "    tm.* ,te.*  from table_meta_info  tm\n" +
            "     left join table_meta_info_extra te on tm.table_name=te.table_name and tm.schema_name=te.schema_name\n" +
            "     where  assess_date = #{assessDate}")
    @ResultMap("BaseResultMap")
    List<TableMetaInfo> selectListWithExtra(@Param("assessDate") String assessDate);
}
